VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "openMSN v0.03"
   ClientHeight    =   6375
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   7545
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6375
   ScaleWidth      =   7545
   StartUpPosition =   2  'CenterScreen
   Begin openMSN.ContactList ContactList1 
      Height          =   4575
      Left            =   4440
      TabIndex        =   8
      Top             =   720
      Width           =   3015
      _ExtentX        =   5318
      _ExtentY        =   8070
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.CommandButton cmdSbo 
      Appearance      =   0  'Flat
      Height          =   495
      Left            =   3960
      MaskColor       =   &H00FFFFFF&
      Picture         =   "frmMain.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   4
      Tag             =   "x"
      Top             =   120
      UseMaskColor    =   -1  'True
      Width           =   375
   End
   Begin VB.CommandButton cmdGroupOffline 
      Appearance      =   0  'Flat
      Height          =   495
      Left            =   3480
      MaskColor       =   &H00FFFFFF&
      Picture         =   "frmMain.frx":0342
      Style           =   1  'Graphical
      TabIndex        =   5
      Tag             =   "x"
      Top             =   120
      UseMaskColor    =   -1  'True
      Width           =   495
   End
   Begin ComctlLib.TreeView tvBuddyList 
      Height          =   4455
      Left            =   120
      TabIndex        =   7
      Tag             =   "x"
      Top             =   720
      Width           =   4215
      _ExtentX        =   7435
      _ExtentY        =   7858
      _Version        =   327682
      LabelEdit       =   1
      LineStyle       =   1
      Style           =   3
      ImageList       =   "ImageList1"
      Appearance      =   1
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "Connect"
      BeginProperty Font 
         Name            =   "Georgia"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2160
      TabIndex        =   3
      Tag             =   "x"
      Top             =   5880
      Width           =   855
   End
   Begin VB.TextBox txtPassword 
      BackColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "Georgia"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   120
      PasswordChar    =   "*"
      TabIndex        =   2
      Tag             =   "x"
      Top             =   5880
      Width           =   1935
   End
   Begin VB.TextBox txtUsername 
      BackColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "Georgia"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Tag             =   "x"
      Text            =   "robin@openmsn.org"
      Top             =   5400
      Width           =   1935
   End
   Begin VB.TextBox txtLog 
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2160
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   5400
      Visible         =   0   'False
      Width           =   2175
   End
   Begin InetCtlsObjects.Inet inetLogin 
      Left            =   3120
      Top             =   5640
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      Protocol        =   5
      RemotePort      =   443
      URL             =   "https://"
   End
   Begin MSWinsockLib.Winsock sckMain 
      Left            =   3840
      Top             =   5760
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label lblName 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   6
      Tag             =   "x"
      Top             =   120
      Width           =   3255
   End
   Begin ComctlLib.ImageList ImageList1 
      Left            =   2760
      Top             =   3840
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   16777215
      _Version        =   327682
      BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
         NumListImages   =   6
         BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0C0C
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":0F5E
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":12B0
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":1602
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":1954
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
            Picture         =   "frmMain.frx":1CA6
            Key             =   ""
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'openMSN MSNP9

Option Explicit

Dim gotString As String
Dim oldString As String

Dim loginTicket As String

Private Sub cmdConnect_Click()
    Connect
End Sub

Private Sub cmdGroupOffline_Click()
    GroupOffline = Not GroupOffline
    SaveSetting App.Title, "Settings", "GroupOffline", IIf((GroupOffline = True), "True", "False")
    UpdateList
End Sub

Private Sub cmdSbo_Click()
    SortByOnline = Not SortByOnline
    SaveSetting App.Title, "Settings", "SortByOnline", IIf((SortByOnline = True), "True", "False")
    UpdateList
End Sub

Private Sub Form_Load()

    Me.Show
    
    ContactList1.ActivateMouse Me.hwnd

    ContactList1.AddParent "Online"
    ContactList1.AddParent "Offline"
    
    SortByOnline = IIf((GetSetting(App.Title, "Settings", "SortByOnline", "False") = "False"), False, True)
    GroupOffline = IIf((GetSetting(App.Title, "Settings", "GroupOffline", "False") = "False"), False, True)
    
    trID_a = -1
    
    If SortByOnline = True Then
        tvBuddyList.Nodes.Add , , "tvOnline", "Online", 1
    End If
    
    tvBuddyList.Nodes.Add , , "tvOffline", "Offline", 2
End Sub

Private Sub Form_Unload(Cancel As Integer)
    End
End Sub

Private Sub inetLogin_StateChanged(ByVal State As Integer)

    If State = 12 Then
        If Len(inetLogin.GetHeader("Authentication-Info")) > 0 Then
            loginTicket = Split(inetLogin.GetHeader("Authentication-Info"), "'")(1)
            Send_Command "USR " & trID() & " TWN S " & loginTicket
        ElseIf Len(inetLogin.GetHeader("WWW-Authenticate")) > 0 Then
                Dim controla
                For Each controla In frmMain.Controls
                    If controla.Tag = "x" Then
                        controla.Enabled = True
                    End If
                Next
                frmMain.lblName = ""
                MsgBox "Login failed!", vbCritical Or vbOKOnly, "Authentication Error"
        Else
            MsgBox inetLogin.ResponseInfo & vbCrLf & inetLogin.GetChunk(250000)
        End If
    End If
    
    Log State
    
End Sub

Private Sub sckMain_Close()
    
    Log "Disconnected"
    
    frmMain.Height = 6855
    
End Sub

Private Sub sckMain_Connect()

    Log "Connected"
    Send_Command "VER " & trID() & " MSNP9 CVR0"

End Sub

Private Sub sckMain_DataArrival(ByVal bytesTotal As Long)

    sckMain.GetData gotString
      
    If Right(gotString, 2) = vbCrLf Then
    
        If Len(oldString) > 0 Then
            oldString = oldString & gotString
            gotString = oldString
        End If
        
        Parse gotString
        oldString = ""
    Else
        oldString = oldString & gotString
    End If

End Sub

Private Sub sckMain_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)

    Log "Error(" & Number & "): " & Description

End Sub

Private Sub tvBuddyList_DblClick()

    If InStr(tvBuddyList.SelectedItem.Key, "@") > 0 Then
                
        Dim i As Integer
        If MessageWindows > 0 Then
            For i = 1 To MessageWindows
                
                If nForm(i).ContactEmail = tvBuddyList.SelectedItem.Key Then
                    nForm(i).ContactName = tvBuddyList.SelectedItem.Text
                    nForm(i).WindowID = i
                    FoundForm = i
                    Exit Sub
                End If
            Next
        End If
        
        MessageWindows = MessageWindows + 1
        ReDim Preserve nForm(MessageWindows)
        Set nForm(MessageWindows) = New frmMessage
        
        nForm(MessageWindows).ContactEmail = tvBuddyList.SelectedItem.Key
        nForm(MessageWindows).ContactName = tvBuddyList.SelectedItem.Text
        nForm(MessageWindows).WindowID = MessageWindows
        FoundForm = MessageWindows
        
        Send_Command "XFR " & trID() & " SB"
    
    End If

End Sub
